const {
    createToken,
    varifyToken
} = require('./token')
let tokenMiddlWare = (req, res, next) => {
    console.log('token拦截器', req.body);
    let token = req.get('token');
    if (!token) {
        return res.send({
            err: -997,
            msg: 'token丢失'
        })
    }
    let tokenState = varifyToken(token);
    console.log(tokenState);
    if (tokenState) {
        if (tokenState.username === req.body.username) {
            next();
        } else {
            res.send({
                err: -998,
                msg: 'token无效'
            })
        }
    } else {
        res.send({
            err: -998,
            msg: 'token失效'
        })
    }
};
module.exports = tokenMiddlWare
